package com.ymatou.iapi.productmanager.testcase.old;

import com.ymatou.iapi.productmanager.parameter.GetNearFutureCategoryBean;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmanager.service.GetNearFutureCategoryCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.LiveCallService;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.utils.EnvSetup;

import org.junit.*;
import org.junit.experimental.categories.Category;

import java.util.Arrays;

/**
*获取最近一场正在进行或者还未开始的扫货现场关联品类
*FreeMaker Template自动生成代码
*/
@TestSuite
@Ignore
public class Ts_GetNearFutureCategory {
	private static GetNearFutureCategoryBean getnearfuturecategoryBean;
	private static GetNearFutureCategoryCall getnearfuturecategoryCall;
	private static Integer sellerId = Integer.valueOf(EnvSetup.getData("productsellerid"));
	private static String sellerName = EnvSetup.getData("productsellername");
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取最近一场正在进行或者还未开始的扫货现场关联品类");
	}

	@Before
	public void caseUp() {
		getnearfuturecategoryBean=new GetNearFutureCategoryBean();
		getnearfuturecategoryCall=new GetNearFutureCategoryCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getnearfuturecategoryCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetNearFutureCategory() {
		Logger.start(true,"获取最近一场还未开始的扫货现场关联品类");
		try {
			AddSellerProductRequest addrop =ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addrop).get("Data").getAsJsonObject().get("ProductId").getAsString();
			int liveId = LiveCallService.createLiveInProgress(sellerName, sellerId).getJSONObject("Data").getInt("ActivityId");

			ProductManagerCallServiceV2.addProductInLives(liveId, Arrays.asList(productId),sellerId);
			getnearfuturecategoryBean.setUserId(sellerId);
			getnearfuturecategoryCall.setData(getnearfuturecategoryBean);
			getnearfuturecategoryCall.callService();			
			Logger.verifyEquals("200",getnearfuturecategoryCall.getString("Code"),"验证Code");
			Logger.verifyEquals(addrop.getProduct().getThirdCategoryId(),Integer.parseInt(getnearfuturecategoryCall.getJsonObject().get("Data").getAsJsonArray().get(0).getAsJsonObject().get("CategoryId").toString()),"验证CategoryId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}